package hacker_rank.oct13;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class AngryChildren {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int N = Integer.parseInt(br.readLine());

		int K = Integer.parseInt(br.readLine());

		int[] ar = new int[N];

		for (int i = 0; i < N; i++) {
			ar[i] = Integer.parseInt(br.readLine());
		}

		solve(ar, N, K);

	}

	private static void solve(int[] ar, int n, int k) {
		Arrays.sort(ar);
		int si = 0;
		int ei = k - 1;
		
		int res = Integer.MAX_VALUE;
		
		while (ei < n) {
			if( (ar[ei] - ar[si]) < res) {
				res = ar[ei] - ar[si];
				
			}
			si++;
			ei++;
		}
		System.out.println(res);
	}

}
